<template>
  <div class="goods-item" @click="itemClick">
    <img v-lazy="showImage" alt="" @load="imgLoad">
    <div class="goods-info">
      <p>{{goodsItem.title}}</p>
      <p><span class="price">{{goodsItem.price}}</span><span class="collect">{{goodsItem.cfav}}</span></p>
    </div>
  </div>
</template>

<script>
  export default {
    name: "GoodsListItem",
    props: {
      goodsItem: {
        type: Object,
        default(){
          return {}
        }
      }
    },
    computed: {
      showImage(){
        return this.goodsItem.image || this.goodsItem.show.img
      }
    },
    methods: {
      imgLoad(){
        if(this.$route.path === '/home'){
          this.$bus.$emit('homeImgLoad')
        }else if(this.$route.path === '/detail'){
          this.$bus.$emit('detailImgLoad')
        }
      },
      itemClick(){
        this.$router.push({
          path: '/detail',
          query: {
            iid: this.goodsItem.iid
          }
        })
      }
    }
  }
</script>

<style scoped>
.goods-item{
  width: 47%;
  position: relative;
  padding-bottom: 36px;
  margin-bottom: 10px;
}
.goods-item img{
  width: 100%;
  border-radius: 5px;
}
.goods-info{
  width: 100%;
  font-size: 13px;
  text-align: center;
  position: absolute;
  bottom: 0;
  left: 0;
}
.goods-info p{
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}
.price{
  color: var(--color-high-text);
  margin-right: 30px;
}
.goods-info .collect{
  position: relative;
}
.goods-info .collect::before{
  content: '';
  display: inline-block;
  position: absolute;
  left: -15px;
  width: 14px;
  height: 14px;
  top: -1px;
  background: url("~assets/img/common/collect.svg") 0 0/14px 14px;
}
</style>